package com.zjsru.controller;

import com.zjsru.pojo.Order;
import com.zjsru.pojo.User;
import com.zjsru.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService OrderService;

    @Autowired
    private RestTemplate restTemplate;
    @GetMapping("/query/{id}")
    public Order queryOrderById(@PathVariable("id") Long orderId) {
        Order order = OrderService.queryOrderById(orderId);
        ServiceInstance instance = nacosServiceDiscovery.getInstance("nacos-user").get(0);
        String url = serviceInstance.getHost()+":"+serviceInstance.getPort();
        User user =  restTemplate.getForObject(url, User.class, order.getUser_Id());
        order.setUser(user);
        return order;
    }
}
